#include "jpshowinfo.h"

JpShowInfo::JpShowInfo()
{

}

JpShowInfo::~JpShowInfo()
{

}

//显示主机信息
void JpShowInfo::showMasterInfo(MastSlaveMap data){
    printf("master:%s\n",data.masterip.toLatin1().data());
    for(int i=0;i<data.slavecount;i++){
        printf("slave:%s\n",data.slaveip[i].toLatin1().data());
    }

}
//显示从机信息
void JpShowInfo::showSlaveInfo(SlaveMastMap data){
    printf("slave:%s---master:%s\n",data.slaveip.toLatin1().data(),data.masterip.toLatin1().data());
}
//显示客户端信息
void JpShowInfo::showClientInfo(QVector<ClientList> _client){
    foreach (ClientList c, _client) {
        qDebug()<<"ID:"<<c.id<<"clientIP:"<<c.ip<<"状态:"<<c.alive<<"socket:"<<c.socket<<"端口:"<<c.port;
    }
}


//显示客户端信息
void JpShowInfo::showClientInfo(QVector<ClientList>* _client){
    foreach (ClientList c, *_client) {
        qDebug()<<"ID:"<<c.id<<"clientIP:"<<c.ip<<"状态:"<<c.alive<<"socket:"<<c.socket<<"端口:"<<c.port;
    }
}

//获得在线的客户端
QVector<ClientList> JpShowInfo::getActiveClient(QVector<ClientList>* _clientlist){
    QVector<ClientList> ret;
    foreach (ClientList c, *_clientlist) {
        if(c.alive==1){
            ret.append(c);
        }
    }
    return ret;
}
//取得客户端信息
ClientList JpShowInfo::getClient(QVector<ClientList>* _clientlist,QTcpSocket* socket){
    ClientList cl;
    QString _ip=socket->peerAddress().toString();
    foreach (ClientList c, *_clientlist) {
        if(c.alive==1&&c.ip==_ip){
            cl=c;
        }
    }
    return cl;
}
